﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Configuration;

namespace parkMonitor.DataBase
{
    public class DBConnection
    {
        public MySqlConnection getConn(string connectionStr)
        {
            MySqlConnection con = null;
            try
            {
                con = new MySqlConnection(ConfigurationManager.AppSettings[connectionStr]);
            }
            catch
            {
                Console.WriteLine("配置文件有误");
            }
            return con;
        }
        public MySqlCommand getComm(string sql, MySqlConnection con)
        {
            MySqlCommand cmd = null;
            try
            {
                cmd = new MySqlCommand(sql, con);
            }
            catch(MySqlException)
            {
                Console.WriteLine("数据库连接异常");
            }
            catch
            {
                Console.WriteLine("sql语句异常");
            }
            return cmd;
        }
    }
}
